﻿<Window x:Class="DeploySources.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		xmlns:v="clr-namespace:DeploySources.View"
		xmlns:vm="clr-namespace:DeploySources.ViewModel"
		xmlns:conv="clr-namespace:DeploySources.Converter"
        mc:Ignorable="d"
        Title="Deploy Sources" Height="350" Width="525" Icon="Resources/DS.ico">
	<Window.Resources>
		<DataTemplate DataType="{x:Type vm:EnsureDataViewModel}">
			<v:EnsureDataView/>
		</DataTemplate>
		<conv:InvertBoolConverter x:Key="InvertBoolConverter"/>
		<Style x:Key="MyWaterMarkStyle" TargetType="{x:Type TextBox}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type TextBox}">
						<Grid>
							<Border Background="White" BorderBrush="#FF7D8683" BorderThickness="1"/>
							<ScrollViewer x:Name="PART_ContentHost" Margin="5,0,0,0" VerticalAlignment="Center" />
							<Label Margin="5,0,0,0" x:Name="WaterMarkLabel" Content="{TemplateBinding Tag}" VerticalAlignment="Center"
                               Visibility="Collapsed" Foreground="Gray" FontFamily="Arial"/>
						</Grid>
						<ControlTemplate.Triggers>
							<MultiTrigger>
								<MultiTrigger.Conditions>
									<Condition Property="Text" Value=""/>
								</MultiTrigger.Conditions>
								<Setter Property="Visibility" TargetName="WaterMarkLabel" Value="Visible"/>
							</MultiTrigger>
							<Trigger Property="IsEnabled" Value="False">
								<Setter Property="Foreground" Value="DimGray"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</Window.Resources>
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="20"/>
			<RowDefinition Height="105"/>
			<RowDefinition/>
		</Grid.RowDefinitions>
		<Menu>
			<MenuItem Header="File">
				<MenuItem Header="Manage Connections" Command="{Binding Path=ManageConnectionsCommand}"></MenuItem>
				<Separator />
				<MenuItem Header="Close" Command="{Binding Path=CloseApplicationCommand}"></MenuItem>
			</MenuItem>
			<MenuItem Header="Info">
				<MenuItem Header="About" Command="{Binding Path=AboutCommand}"></MenuItem>
			</MenuItem>
		</Menu>
		<Grid Grid.Row="1" Background="#FFEEEEEE">
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition/>
				<RowDefinition/>
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition/>
				<ColumnDefinition Width="100"/>
				<ColumnDefinition Width="35"/>
			</Grid.ColumnDefinitions>
			<ComboBox Grid.Row="0" Grid.Column="0" Margin="3" 
					  ItemsSource="{Binding Connections}" 
					  SelectedValue="{Binding Connection}" 
					  Text="{Binding Connection.Url}"
					  IsEnabled="{Binding Path=DataContext.IsConnected, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Converter={StaticResource InvertBoolConverter}}"
					  IsEditable="True" 
					  IsTextSearchEnabled="True" 
					  TextSearch.TextPath="Url">
				<ComboBox.ItemTemplate>
					<DataTemplate>
						<TextBlock Text="{Binding Url}"/>
					</DataTemplate>
				</ComboBox.ItemTemplate>
			</ComboBox>
			<Button Grid.Row="0"  Grid.Column="1" Content="{Binding ConnectionText}" Margin="3" Command="{Binding Path=ConnectionCommand}" />
			<Image Grid.Row="0" Grid.Column="2" Source="{Binding Path=ConnectedImage}"></Image>
			<TextBox Grid.Row="1" Grid.Column="0" Margin="3" 
					 Text="{Binding Connection.ArtefactFile}"
					 ToolTipService.ShowOnDisabled="True"
					 ToolTip="{Binding Connection.ArtefactFile}"
					 IsEnabled="False"
					 Style="{StaticResource MyWaterMarkStyle}"
					 Tag="Artefacts file">
			</TextBox>
			<Button Grid.Row="1"  Grid.Column="1" Margin="3" Content="..." Command="{Binding Path=SelectArtefactFileCommand}" IsEnabled="{Binding Path=DataContext.IsConnected, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Converter={StaticResource InvertBoolConverter}}"/>
			<StackPanel Grid.Row="2" Grid.ColumnSpan="3" Orientation="Horizontal" DataContext="{Binding Path=Connection}">
				<Label VerticalAlignment="Center">Credentials: </Label>
				<TextBox IsEnabled="{Binding Path=DataContext.IsConnected, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Converter={StaticResource InvertBoolConverter}}" Style="{StaticResource MyWaterMarkStyle}" Text="{Binding Path=Username}" Tag="Username" MinWidth="150" Margin="5"></TextBox>
				<TextBox IsEnabled="{Binding Path=DataContext.IsConnected, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Converter={StaticResource InvertBoolConverter}}" Style="{StaticResource MyWaterMarkStyle}" Text="{Binding Path=Password}" Tag="Password" MinWidth="150" Margin="5" Padding="0"/>
				<CheckBox IsEnabled="{Binding Path=DataContext.IsConnected, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Converter={StaticResource InvertBoolConverter}}" VerticalAlignment="Center" Margin="10,0,0,0" IsChecked="{Binding Path=IsSharePointOnline}">Is SPO</CheckBox>
			</StackPanel>
		</Grid>
		<ContentControl Grid.Row="2" Content="{Binding ViewModel}"/>
	</Grid>
</Window>
